package com.wenda.homeschooedu.daoimpl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.wenda.homeschooedu.DB.JDBCConnection;
import com.wenda.homeschooedu.DB.DB.Table;
import com.wenda.homeschooedu.dao.IReturnBasicInform;
import com.wenda.homeschooedu.model.ParentBasicInform;

public class ReturnBasicInformService implements IReturnBasicInform {
	JDBCConnection jdbcConnection;
	Statement statement;

	public ReturnBasicInformService() {
		jdbcConnection = new JDBCConnection();
		statement = jdbcConnection.getStm();
	}

	public ParentBasicInform returnBasicInform(String username, String password) {
		String sql = String.format(Table.BasicInformation.SQL.SELECT, username,
				password);
		ParentBasicInform basicInform = new ParentBasicInform();

		try {
			ResultSet resultSet = statement.executeQuery(sql);
			resultSet.next();
			basicInform.setClass_id(resultSet.getInt(resultSet
					.findColumn("class_id")));
			basicInform.setClass_name(resultSet.getString(resultSet
					.findColumn("class_name")));
			basicInform.setMaster_id(resultSet.getInt(resultSet
					.findColumn("teacher_id")));
			basicInform.setMaster_name(resultSet.getString(resultSet
					.findColumn("teacher_name")));
			basicInform.setParent_id(resultSet.getInt(resultSet
					.findColumn("parent_id")));
			basicInform.setParent_name(resultSet.getString(resultSet
					.findColumn("parent_name")));
			basicInform.setStudent_id(resultSet.getInt(resultSet
					.findColumn("student_id")));
			basicInform.setStudentName(resultSet.getString(resultSet
					.findColumn("student_name")));
			basicInform.setUserName(resultSet.getString(resultSet
					.findColumn("parent_username")));

			return basicInform;

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}

	}

}
